function checkLocation(seq) {
    str = eval('document.markAndPackForm.select_'+seq+'.checked');
    var cnt = document.markAndPackForm.count.value;
	var maxVal = 0;
	if(cnt!=1)
	{
        if(str==false)
		{
            document.markAndPackForm.priority[seq].disabled=true;
            document.markAndPackForm.split[seq].disabled=true;
            document.markAndPackForm.capacityWeek[seq].disabled=true;
            document.markAndPackForm.normalCost[seq].disabled=true;
            document.markAndPackForm.expressCost[seq].disabled=true;
            document.markAndPackForm.locationName[seq].disabled=true;
            document.markAndPackForm.normalCycleTime[seq].disabled=true;
            document.markAndPackForm.expressCycleTime[seq].disabled=true;
			// added to set the default priority by ravikanth
			maxVal =  document.markAndPackForm.priority[seq].value;
			for ( var y =0 ; y < cnt ; y++ )
			{
				temp   = document.markAndPackForm.priority[y].value;
				if( temp > maxVal && maxVal != 0)
				{
					document.markAndPackForm.priority[y].value = parseInt(document.markAndPackForm.priority[y].value) -1;
				}
			}

			document.markAndPackForm.priority[seq].value='';
        }
        if(str==true)
		{
            document.markAndPackForm.priority[seq].disabled=false;
            document.markAndPackForm.split[seq].disabled=false;
            document.markAndPackForm.capacityWeek[seq].disabled=false;
            document.markAndPackForm.normalCost[seq].disabled=false;
            document.markAndPackForm.expressCost[seq].disabled=false;
            //document.markAndPackForm.locationName[seq].disabled=false;
            document.markAndPackForm.normalCycleTime[seq].disabled=false;
            document.markAndPackForm.expressCycleTime[seq].disabled=false;
			// added to set the default priority by ravikanth
			for ( var y =0 ; y < cnt ; y++ )
			{
				temp   = document.markAndPackForm.priority[y].value;
				if( temp > maxVal)
				{
					maxVal = temp
				}
			}		
			document.markAndPackForm.priority[seq].value= parseInt(maxVal)+1 ;
        }
	}
    else
	{
        if(str==false)
		{
			document.markAndPackForm.priority.disabled=true;
			document.markAndPackForm.split.disabled=true;
			document.markAndPackForm.capacityWeek.disabled=true;
			document.markAndPackForm.normalCost.disabled=true;
			document.markAndPackForm.expressCost.disabled=true;
			document.markAndPackForm.locationName.disabled=true;
			document.markAndPackForm.normalCycleTime.disabled=true;
			document.markAndPackForm.expressCycleTime.disabled=true;
			document.markAndPackForm.priority.value='';
		}
        if(str==true)
		{
			document.markAndPackForm.priority.disabled=false;
			document.markAndPackForm.split.disabled=false;
			document.markAndPackForm.capacityWeek.disabled=false;
			document.markAndPackForm.normalCost.disabled=false;
			document.markAndPackForm.expressCost.disabled=false;
			//document.markAndPackForm.locationName.disabled=false;
			document.markAndPackForm.normalCycleTime.disabled=false;
			document.markAndPackForm.expressCycleTime.disabled=false;
			document.markAndPackForm.priority.value=1;
		}
	}
}

function whileLoad()
{
    var cnt = document.markAndPackForm.count.value;
	if(cnt==1)
	{ 
		str  = eval('document.markAndPackForm.select_0.checked');
		if(str==false){
			document.markAndPackForm.priority.disabled=true;
			document.markAndPackForm.split.disabled=true;
			document.markAndPackForm.capacityWeek.disabled=true;
			document.markAndPackForm.normalCost.disabled=true;
    		document.markAndPackForm.expressCost.disabled=true;
			document.markAndPackForm.locationName.disabled=true;
			document.markAndPackForm.normalCycleTime.disabled=true;
			document.markAndPackForm.expressCycleTime.disabled=true;
		}
		if(str==true){
			document.markAndPackForm.priority.disabled=false;
			document.markAndPackForm.split.disabled=false;
			document.markAndPackForm.capacityWeek.disabled=false;
			document.markAndPackForm.normalCost.disabled=false;
			document.markAndPackForm.expressCost.disabled=false;
			//document.markAndPackForm.locationName.disabled=false;
			document.markAndPackForm.normalCycleTime.disabled=false;
			document.markAndPackForm.expressCycleTime.disabled=false;
		}
	}
	else{
	    for(var i=0;i<cnt;i++){
        	str  = eval('document.markAndPackForm.select_'+i+'.checked');
	    	if(str==false){
		    	document.markAndPackForm.priority[i].disabled=true;
			    document.markAndPackForm.split[i].disabled=true;
			    document.markAndPackForm.capacityWeek[i].disabled=true;
			    document.markAndPackForm.normalCost[i].disabled=true;
			    document.markAndPackForm.expressCost[i].disabled=true;
			    document.markAndPackForm.locationName[i].disabled=true;
			    document.markAndPackForm.normalCycleTime[i].disabled=true;
			    document.markAndPackForm.expressCycleTime[i].disabled=true;
		    }
		    else if(str==true){
			    document.markAndPackForm.priority[i].disabled=false;
			    document.markAndPackForm.split[i].disabled=false;
			    document.markAndPackForm.capacityWeek[i].disabled=false;
			    document.markAndPackForm.normalCost[i].disabled=false;
			    document.markAndPackForm.expressCost[i].disabled=false;
			    //document.markAndPackForm.locationName[i].disabled=false;
			    document.markAndPackForm.normalCycleTime[i].disabled=false;
			    document.markAndPackForm.expressCycleTime[i].disabled=false;
	    	}
	    }
   }
}

function saveMarkAndPack()
{
	
	var cnt						= document.markAndPackForm.count.value;
	var pa						= document.getElementById("message");
	var std_unit_cost			= document.markAndPackForm.standardUnitCost.value;
	var lot_scrap_yield_limit   = document.markAndPackForm.lotScrapYieldLimit.value;
	var target_yield			= document.markAndPackForm.targetYield.value;
	var vendorPriority			=  null;
	var vendorCnt				= 0;

	// added by ravikanth on 30-Sep-2003

	if(trim(document.markAndPackForm.productName.value)=='')
	{
		pa.innerHTML = " Mark and Pack Part Number cannot be null or contain spaces ";	
		document.markAndPackForm.productName.value = '';
		document.markAndPackForm.productName.focus();
		return;
	}
	else
	{
		document.markAndPackForm.productName.value = document.markAndPackForm.productName.value.trim();
	}

	if( typeof document.markAndPackForm.locationName.length == 'undefined' )
	{
		if ( document.markAndPackForm.select_0.checked+"" == "true" )
		{
			vendorCnt++;
		}

		if( vendorCnt > 0 && ( document.markAndPackForm.priority.value =='0' || document.markAndPackForm.priority.value.trim().length == 0 ) )
		{
			pa.innerHTML = "Priority cannot 0 or empty ";	
			document.markAndPackForm.priority.value='';
			document.markAndPackForm.priority.focus();
			return; 
		}
	}
	else
	{
		vendorPriority = new Array(document.markAndPackForm.locationName.length);
		for (var x=0 ; x < document.markAndPackForm.locationName.length ; x++ )
		{
			var temp = eval("document.markAndPackForm.select_"+x);

			if( temp.checked+"" == "true" )
			{
				vendorCnt++;
				if (document.markAndPackForm.priority[x].value == 0 || document.markAndPackForm.priority[x].value.trim().length == 0 )
				{
					
					pa.innerHTML = "Vendor priority cannot 0 or empty ";	
					document.markAndPackForm.priority[x].value = '';
					document.markAndPackForm.priority[x].focus();
					return; 
				}
				vendorPriority[x] = document.markAndPackForm.priority[x].value
			}
		}
	}

	if( vendorCnt == 0)
	{
		pa.innerHTML = "Should select atleast one vendor";	
		return; 
	}

	if( vendorCnt > 1 )
	{
		
		for ( y=0 ; y < vendorPriority.length -1 ; y++ )
		{
			for ( z = y+1 ; z < vendorPriority.length ; z++ )
			{
				if( vendorPriority[y] != null && vendorPriority[z] != null && vendorPriority[y] != 0 && vendorPriority[z] !=0 )
				{
					if ( vendorPriority[z] == vendorPriority[y])
					{
						pa.innerHTML = "Two vendor priorities cannot be same ";	
						return; 
					}
				}
			}
		}
	}


	var flag = checkDupInProduct(document.markAndPackForm.productName,document.markAndPackForm.dupProductName);
	if( flag != -1 )
	{
		if( typeof document.markAndPackForm.dupProductName.length == 'undefined' )
		{
			document.markAndPackForm.dupProductName.focus();
		}
		else
		{
			document.markAndPackForm.dupProductName[flag].focus();	
		}
		pa.innerHTML = "Two Part numbers cannot be same";	
		return; 
	}
	
	if(std_unit_cost!=''){
		if(!isFloat(std_unit_cost)){	
 	    pa.innerHTML = "Please enter valid Standard Unit Cost,It must be float";
		document.markAndPackForm.standardUnitCost.select();
		document.markAndPackForm.standardUnitCost.focus();
		return;
		}	
	}

	if(lot_scrap_yield_limit!=''){
		if(!isFloat(lot_scrap_yield_limit)){	
 	    pa.innerHTML = "Please enter valid Lot Scrap Yield Limit,It must be float";
		document.markAndPackForm.lotScrapYieldLimit.select();
		document.markAndPackForm.lotScrapYieldLimit.focus();
		return;
		}	
	}

	if(target_yield!=''){
		if(!isFloat(target_yield)){	
 	    pa.innerHTML = "Please enter valid Target Yield,It must be Float";
		document.markAndPackForm.targetYield.select();
		document.markAndPackForm.targetYield.focus();
		return;
		}	
	}

	if(cnt==1)
	{ 
		str   = eval('document.markAndPackForm.select_0.checked');

		if(str==true){
            var priority		= document.markAndPackForm.priority.value;
            var split			= document.markAndPackForm.split.value;
            var capacity_week   = document.markAndPackForm.capacityWeek.value;
            var normal_cost		= document.markAndPackForm.normalCost.value;
            var express_cost	= document.markAndPackForm.expressCost.value;
            var normal_time		= document.markAndPackForm.normalCycleTime.value;
            var express_time	= document.markAndPackForm.expressCycleTime.value;

			if(priority!=''){
				if (!isInteger(priority)){
                    pa.innerHTML = "Please enter valid Priority,It must be number";
                    document.markAndPackForm.priority.select();
                    document.markAndPackForm.priority.focus();
                    return;
				}
			}

			if(split!=''){
				if (!isFloat(split)){
                    pa.innerHTML = "Please enter valid Split,It must be float";
                    document.markAndPackForm.split.select();
                    document.markAndPackForm.split.focus();
                    return;
                }
    		}
    		if(capacity_week!=''){
				if (!isInteger(capacity_week)){
	    			pa.innerHTML = "Please enter valid Capacity Per Week,It must be number";
		    		document.markAndPackForm.capacityWeek.select();
			    	document.markAndPackForm.capacityWeek.focus();
				    return;
				}
			}

			if(normal_cost!=''){
				if (!isFloat(normal_cost)){
			    	pa.innerHTML = "Please enter valid Normal Cost,It must be float";
				    document.markAndPackForm.normalCost.select();
				    document.markAndPackForm.normalCost.focus();
				    return;
				}
			}

			if(express_cost!=''){
				if (!isFloat(express_cost)){
			    	pa.innerHTML = "Please enter valid Express Cost,It must be float";
				    document.markAndPackForm.expressCost.select();
				    document.markAndPackForm.expressCost.focus();
				    return;
				}
			}

			if(normal_time!=''){
				if (!isInteger(normal_time)){
			    	pa.innerHTML = "Please enter valid Normal Time,It must be number";
				    document.markAndPackForm.normalCycleTime.select();
				    document.markAndPackForm.normalCycleTime.focus();
				    return;
				}
			}
			if(express_time!=''){
				if (!isInteger(express_time)){
    				pa.innerHTML = "Please enter valid Express Time,It must be number";
	    			document.markAndPackForm.expressCycleTime.select();
		    		document.markAndPackForm.expressCycleTime.focus();
			    	return;
				}
			}
		}
	}
	else{
        for(var i=0;i<cnt;i++){
		    var str = eval('document.markAndPackForm.select_'+i+'.checked');
		    if(str==true){
                var priority		= document.markAndPackForm.priority[i].value;
                var split			= document.markAndPackForm.split[i].value;
                var capacity_week   = document.markAndPackForm.capacityWeek[i].value;
                var normal_cost		= document.markAndPackForm.normalCost[i].value;
                var express_cost	= document.markAndPackForm.expressCost[i].value;
                var normal_time		= document.markAndPackForm.normalCycleTime[i].value;
                var express_time	= document.markAndPackForm.expressCycleTime[i].value;

                if(priority!=''){
                    if (!isInteger(priority)){
                        pa.innerHTML = "Please enter valid Priority,It must be number";
                        document.markAndPackForm.priority[i].select();
                        document.markAndPackForm.priority[i].focus();
                        return;
                    }
                }

            if(split!=''){
                if (!isFloat(split)){
                    pa.innerHTML = "Please enter valid Split,It must be float";
                    document.markAndPackForm.split[i].select();
                    document.markAndPackForm.split[i].focus();
                    return;
                }
            }

            if(capacity_week!=''){
                if (!isInteger(capacity_week)){
                    pa.innerHTML = "Please enter valid Capacity Per Week,It must be number";
                    document.markAndPackForm.capacityWeek[i].select();
                    document.markAndPackForm.capacityWeek[i].focus();
                    return;
                }
            }

            if(normal_cost!=''){
                if (!isFloat(normal_cost)){
                    pa.innerHTML = "Please enter valid Normal Cost,It must be float";
                    document.markAndPackForm.normalCost[i].select();
                    document.markAndPackForm.normalCost[i].focus();
                    return;
                }
            }

            if(express_cost!=''){
                if (!isFloat(express_cost)){
                    pa.innerHTML = "Please enter valid Express Cost,It must be float";
                    document.markAndPackForm.expressCost[i].select();
                    document.markAndPackForm.expressCost[i].focus();
                    return;
                }
            }

            if(normal_time!=''){
                if (!isInteger(normal_time)){
                    pa.innerHTML = "Please enter valid Normal Time,It must be number";
                    document.markAndPackForm.normalCycleTime[i].select();
                    document.markAndPackForm.normalCycleTime[i].focus();
                return;
                }
            }
            if(express_time!=''){
                if (!isInteger(express_time)){
                    pa.innerHTML = "Please enter valid Express Time,It must be number";
                    document.markAndPackForm.expressCycleTime[i].select();
                    document.markAndPackForm.expressCycleTime[i].focus();
                    return;
                }
            }
		}
	}
 }
    if(cnt!=1){
	    for(var i=0;i<cnt;i++){
            document.markAndPackForm.priority[i].disabled=false;
            document.markAndPackForm.split[i].disabled=false;
            document.markAndPackForm.capacityWeek[i].disabled=false;
            document.markAndPackForm.normalCost[i].disabled=false;
            document.markAndPackForm.expressCost[i].disabled=false;
            document.markAndPackForm.locationName[i].disabled=false;
            document.markAndPackForm.normalCycleTime[i].disabled=false;
            document.markAndPackForm.expressCycleTime[i].disabled=false;
            document.markAndPackForm.locationName[i].disabled=false;
    	}
	}
	else{
		document.markAndPackForm.priority.disabled=false;
		document.markAndPackForm.split.disabled=false;
		document.markAndPackForm.capacityWeek.disabled=false;
		document.markAndPackForm.normalCost.disabled=false;
		document.markAndPackForm.expressCost.disabled=false;
		document.markAndPackForm.locationName.disabled=false;
		document.markAndPackForm.normalCycleTime.disabled=false;
		document.markAndPackForm.expressCycleTime.disabled=false;
		document.markAndPackForm.locationName.disabled=false;
		}
	document.markAndPackForm.submit();
}